package com.bbx.taxi.client.Task;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.AsyncTask;

import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.official.passanger.Official_VclassInfoBuild;
import com.bbx.api.sdk.model.official.passanger.Official_VclassInfoBuild;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Vehicle;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Vehicle.VehicleList;
import com.bbx.api.sdk.model.official.passanger.Return.Official_VclassInfo;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.official.passanger.Officail_VclassNet;
import com.bbx.api.sdk.net.official.passanger.Official_VclassInfoNet;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Task.BaseAsyncTask;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.official.R;

/** 
 * @Path com.bbx.taxi.client.Task.MyVclassInfoTask.java
 * @Author 严旭文
 * @Date 2016-1-28 下午6:51:52
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 * 车型具体信息
 */
public class MyVclassInfoTask {
	private Activity context;
	private MyApplication mApplication;
	public static MyVclassInfoTask instance;
	public VclassInfoTask mVclassTask;
	public interface OnVclassInfoListener {
		/**
		 *车型列表，求完毕返回list为空则失败
		 */
		public void onVclassInfo(Official_VclassInfo mOfficial_VclassInfo,String class_id);
	}

	static OnVclassInfoListener mOnVclassInfoListener = null;

	public static void setOnVclassInfoListener(OnVclassInfoListener l) {
		mOnVclassInfoListener = l;
	}
	public static MyVclassInfoTask getInstance(Activity context,
			String tc_id,String class_id) {
		instance = new MyVclassInfoTask(context, tc_id,class_id);
		return instance;
	}
	public MyVclassInfoTask(Activity context,String tc_id,String class_id) {
		this.context = context;
		getVclass(tc_id,class_id);
	}
	/**
	 * 获取车型列表
	 */
	public void getVclass(String tc_id,String class_id) {
		Official_VclassInfoBuild mOfficial_VclassInfoBuild = new Official_VclassInfoBuild(context);
		mOfficial_VclassInfoBuild.tc_id=tc_id;
		mOfficial_VclassInfoBuild.class_id=class_id;
		mVclassTask = new VclassInfoTask(context, mOfficial_VclassInfoBuild);
		mVclassTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	private class VclassInfoTask extends BaseAsyncTask {

		private Official_VclassInfoBuild mOfficial_VclassInfoBuild;

		public VclassInfoTask(Activity context, Official_VclassInfoBuild mOfficial_VclassInfoBuild) {
			super(context,false);
			this.mOfficial_VclassInfoBuild = mOfficial_VclassInfoBuild;
		}

		@Override
		public void onSuccess(Object object) {
			if (object != null) {
				Official_VclassInfo mOfficial_VclassInfo = (Official_VclassInfo)object;
				if(mOfficial_VclassInfo!=null&&mOfficial_VclassInfo.getInfo()!=null){
					if (mOnVclassInfoListener != null) {
						mOnVclassInfoListener.onVclassInfo(mOfficial_VclassInfo,mOfficial_VclassInfoBuild.class_id);
	                }
				}else{
					if (mOnVclassInfoListener != null) {
						mOnVclassInfoListener.onVclassInfo(null,mOfficial_VclassInfoBuild.class_id);
	                }
				}
			

			} else {
				ToastUtil.showToast(context, R.string.no_network);
				if (mOnVclassInfoListener != null) {
					mOnVclassInfoListener.onVclassInfo(null,mOfficial_VclassInfoBuild.class_id);
				}
			}
		}

		@Override
		public void onFailed(int status, String msg) {
			ToastUtil.showToast(context, R.string.no_network);
			if (mOnVclassInfoListener != null) {
				mOnVclassInfoListener.onVclassInfo(null,mOfficial_VclassInfoBuild.class_id);
			}
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mOfficial_VclassInfoBuild).getJson();
			return new Official_VclassInfoNet(context, json);
		}
	}

}
